package com.dingli.controller;

import com.dingli.framework.entity.Customtraining;
import com.dingli.framework.entity.Trainmember;
import com.dingli.framework.util.Response;
import com.dingli.service.ICustomtrainingService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

@CrossOrigin("*")
@RestController
@RequestMapping("/customtraining")
@Api(tags = "定制化培训管理")
public class CustomtrainingController {

    @Autowired
    private ICustomtrainingService iCustomtrainingService;

    @GetMapping("/CTselectList")
    @ApiOperation("定制化培训表信息列表查询")
    public Response<PageInfo<Customtraining>> CTselectList(@ApiParam("查询条件")
                                                        @RequestParam(required = false) String search,
                                                           @ApiParam("页码") @RequestParam(required = false) Integer pageNum,
                                                           @ApiParam("页面大小")
                                                        @RequestParam(required = false) Integer pageSize) {
        return iCustomtrainingService.CTselectList(search, pageNum, pageSize);
    }

    @GetMapping("/CTselectAll")
    @ApiOperation("定制化培训表信息详情查看")
    public Response<List<Customtraining>>CTselectAll(@ApiParam("定制化培训表ID") @RequestParam Long ctId) {
        return iCustomtrainingService.CTselectAll(ctId);
    }

    @PostMapping("/CTupdateState")
    @ApiOperation("定制化培训表审核通过")
    public Response<Object> CTupdateState(@ApiParam("审核通过") @RequestBody String ctId) {

        return iCustomtrainingService.CTupdateState(ctId);
    }

    @PostMapping("/CTupdate")
    @ApiOperation("定制化培训表审核不通过")
    public Response<Object> CTupdate(@ApiParam("审核不通过") @RequestBody String ctId) {
        return iCustomtrainingService.CTupdate(ctId);
    }

    @RequestMapping("/CTselect")
    @CrossOrigin
    @ApiOperation("查询所有不通过定制化培训表")
    public HashMap<Object, Object> CTselect(@ApiParam("定制化培训表不通过") @RequestParam String ctId){
        Response<List<Customtraining>> list = iCustomtrainingService.CTselect("123456");
        HashMap<Object, Object> customtraining = new HashMap<>();
        customtraining .put("Customtraining",list);
        customtraining.put("size",list.getData().size());
        return customtraining;
    }

    @PostMapping("/CTinsert")
    @ApiOperation("定制化培训信息新增")
    public Object CTinsert(@ApiParam("定制化培训信息") @RequestBody Customtraining customtraining) {
        return iCustomtrainingService.CTinsert(customtraining);
    }

    @PostMapping("/CTupdateById")
    @ApiOperation("定制化培训信息修改")
    public Response<Object> CTupdateById(@ApiParam("修改定制化培训信息") @RequestBody Customtraining customtraining) {

        return iCustomtrainingService.CTupdateById(customtraining);
    }

    @GetMapping("/CTdeleteById")
    @ApiOperation("定制化培训信息删除")
    public Response<Object> CTdeleteById(@ApiParam("定制化培训ID") @RequestParam Long ctId) {
        return iCustomtrainingService.CTdeleteById(ctId);
    }

}
